#ifndef _FILE_LIST_H_
#define _FILE_LIST_H_


namespace LuaPlus
{
    class LuaState;
}
#include <vector>
#include <string>
#include <time.h>

namespace script 
{

class	FileList
{
public:
	FileList();
	~FileList();
	void						Build(const std::string& Path);
	void						Reset();
	int							GetFileC();
	std::string					GetFileName(int Index);
	std::string					GetBaseFileName(int Index);
	std::string					GetExtension(int Index);
	std::string					GetFileDate(int Index);
	bool						IsDirectory(int Index)	{ return CheckFlag(Index, FF_DIRECTORY); };
	bool						IsHidden(int Index)		{ return CheckFlag(Index, FF_HIDDEN); };
	bool						IsSystem(int Index)		{ return CheckFlag(Index, FF_SYSTEM); };
	bool						IsArchive(int Index)	{ return CheckFlag(Index, FF_ARCHIVE); };
	bool						IsReadOnly(int Index)	{ return CheckFlag(Index, FF_READONLY); };

	void						SortNumber();

	static FileList*			SearchDir(const std::string& Path);
	static	void				Register(LuaPlus::LuaState* _pScript);


	struct				FileFullData
	{
		FileFullData() :
			Checksum(0),
			FileSize(0),
			Exists(false),
			Flags(0)
		{
		}
		std::string			Name;
		bool				Exists;
		unsigned int		Checksum;
		unsigned int		FileSize;
		time_t				LastTouched;
		unsigned int		Flags;
	};
	// functionality for checking a specific file for data
	static bool				CheckFile(const std::string& File, FileFullData& Data, bool GetCRC = false);
private:
	enum						FILE_FLAGS
	{
		FF_DIRECTORY	=	0x01 << 0,
		FF_HIDDEN		=	0x01 << 1,
		FF_SYSTEM		=	0x01 << 2,
		FF_READONLY		=	0x01 << 3,
		FF_ARCHIVE		=	0x01 << 4
	};
	struct	FileInfo
	{
		FileInfo()
		{
			Flags = 0;
		}

		std::string				Name;
		std::string				Date;
		unsigned int			Flags;
	};
	FileInfo*					GetFileInfo(int Index);
	bool						CheckFlag(int Index, unsigned long Flag);
	static bool					SortByNumber( const FileInfo& A,  const FileInfo& B );


	std::vector<FileInfo>			m_Files;
};

} // namespace script 


#endif // _FILE_LIST_H_